/**
 * cluelog控制器
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.controller;


import com.sxf.crm.dto.ClueLogDTO;
import com.sxf.crm.service.ClueLogService;
import com.sxf.crm.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 线索日志管理REST控制器
 */
@RestController
@RequestMapping("/api/clue-logs")
@RequiredArgsConstructor
public class ClueLogController {
    
    private static final Logger logger = LoggerFactory.getLogger(ClueLogController.class);
    private final ClueLogService clueLogService;
    
    @GetMapping("/clue/{clueId}")
    @PreAuthorize("hasAuthority('clue:view')")
    public ResponseEntity<List<ClueLogDTO>> getClueLogsByClueId(@PathVariable Long clueId) {
        logger.debug("获取线索操作日志: clueId={}", clueId);
        return ResponseEntity.ok(clueLogService.getLogsByClueId(clueId));
    }
    
    @GetMapping("/operator/{operatorId}")
    @PreAuthorize("hasAuthority('clue:view')")
    public ResponseEntity<List<ClueLogDTO>> getClueLogsByOperator(@PathVariable Long operatorId) {
        logger.debug("获取操作人的操作日志: operatorId={}", operatorId);
        return ResponseEntity.ok(clueLogService.getLogsByOperator(operatorId));
    }
    
    @GetMapping("/my")
    @PreAuthorize("hasAuthority('clue:view')")
    public ResponseEntity<List<ClueLogDTO>> getMyCluelogs() {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        logger.debug("获取当前用户的操作日志: userId={}", currentUserId);
        return ResponseEntity.ok(clueLogService.getLogsByOperator(currentUserId));
    }
}